package com.dks.repository.impl;

import java.util.List;
import java.util.Map;

import com.dks.mapper.SignInMapper;
import com.dks.mapper.StudentClassMapper;
import com.dks.models.QsClass;
import com.dks.models.SignIn;
import com.dks.models.student.StudentClass;
import com.dks.repository.ISignInRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class SignInRepository implements ISignInRepository {

    private SignInMapper signInMapper;

    private StudentClassMapper studentClassMapper;

    @Autowired
    public SignInRepository(final SignInMapper signInMapperIn,
                            final StudentClassMapper studentClassMapper) {
        this.signInMapper = signInMapperIn;
        this.studentClassMapper = studentClassMapper;
    }

    @Override
    public Integer insert(SignIn signIn) {
        return signInMapper.insert(signIn);
    }

    @Override
    public Integer update(SignIn signIn) {
        return signInMapper.update(signIn);
    }

    @Override
    public Integer delete(Integer id) {
        return signInMapper.delete(id);
    }

    @Override
    public SignIn select(Integer id) {
        return signInMapper.select(id);
    }

    @Override
    public Integer cntByMap(Map<String, Object> map) {
        return signInMapper.cntByMap(map);
    }

    @Override
    public List<Integer> getByMap(Map<String, Object> map) {
        return signInMapper.getByMap(map);
    }

    @Override
    public List<SignIn> getByMapList(Map<String, Object> map) {
        return signInMapper.getByMapList(map);
    }

    @Override
    public Integer updateByCode(SignIn signIn) {
        return signInMapper.updateByCode(signIn);
    }

    @Override
    public SignIn selectByBfCode(String bfCode) {
        return signInMapper.selectByBfCode(bfCode);
    }

    /**
     * @Author: Ah Nan
     * @Description: 签到
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: teacher_id 老师id
     * @Param: classroom_id 教室id
     * @Param: student_id 学生id
     * @return:
     * @throw: 请描述异常信息
     */
    @Override
    public ResultModel<Object> addSignIn(StudentClass studentClass) {
        studentClass.setClassAttendStatus("SIGN_IN");
        int row = studentClassMapper.update(studentClass);
        if (row == 1) {
            return Result.makeResult(ResultInfo.SUCCESS, row);
        } else {
            return Result.makeResult(ResultInfo.ERR_DATA_STRUCTURE, row);
        }
    }
}
